#include"comm.hpp"
#include<unistd.h>

int main()
{
    key_t k = getkey();
    printf("key:0x%x\n",k);//%x 以16进程进行打印

    int shmid = createShm(k);
    printf("shmid:%d\n",shmid);



    char* start = (char*)attachShm(shmid);
    printf("attach success , address start : %p\n",start);

    //使用

    while(true)
    {
        printf("client say : %s\n",start);

        struct shmid_ds ds;
        shmctl(shmid , IPC_STAT , &ds);
        printf("获取信息：size:%d,pid:%d,myself:%d,key:0x%x",\
                ds.shm_segsz,ds.shm_cpid,getpid(),ds.shm_perm.__key);
        sleep(1);
    }
    //去关联
    detachShm(start);

    //删除共享内存
    delShm(shmid);

    // std::cout<<"64位下的指针大小:"<<sizeof(void*)<<std::endl;
    return 0;
}